package com.poetry.jianjia.presenter;

import com.poetry.jianjia.BaseApplication;
import com.poetry.jianjia.net.Wan;

import java.lang.ref.WeakReference;

/**
 * @author 裴云飞
 * @date 2021/1/26
 */
public abstract class BasePresenter<T> {

    protected WeakReference<T> mView;
    protected Wan mWan;

    public BasePresenter(T view) {
        this.mView = new WeakReference<>(view);
        mWan = BaseApplication.getInstance().getJianJia().create(Wan.class);
        init();
    }

    public T getView() {
        return mView.get();
    }

    /**
     * 做presenter中的数据初始化
     */
    public abstract void init();

    /**
     * 做销毁时移除数据
     */
    public void onDestroy(){
        if (mView != null) {
            mView.clear();
            mView = null;
        }
    }
}
